from flask import Flask
from flask_socketio import SocketIO
from ws.api import StationNamespace
from stationpilot.servers.common.shared import mq_client

# Flask & SocketIO
app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins="*")

# 注册命名空间
socketio.on_namespace(StationNamespace("/ws"))

if __name__ == "__main__":
    # 启动 MQTT
    mq_client.set_socketio_instance(socketio)
    # 启动 WS 网关
    socketio.run(app, host="0.0.0.0", port=8000)
